package com.colorfruit.admin.control.controller;

import com.colorfruit.admin.business.service.ProductService;
import com.colorfruit.admin.business.service.impl.ProductServiceImpl;
import com.colorfruit.admin.pojo.enums.ErrorCodeEnum;
import com.colorfruit.framework.model.pojo.BaseResult;
import com.colorfruit.framework.redis.RedisCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    RedisCache redisCache;

    @Autowired
    ProductService productService;

    @GetMapping("/clearCashWithKey")
    public BaseResult clearCashWithKey(String key){
        try {
            log.info("清除缓存start key = {}", key);
            redisCache.deleteCacheWithPattern("*" + key + "*");
            log.info("清除缓存end key = {}", key);
            return new BaseResult(ErrorCodeEnum.SUCCESS);
        }catch (Exception e){
            log.error("# [OUT] errorMessage: " + e.getMessage(), e);
            return new BaseResult(ErrorCodeEnum.SYSTEM_ERROR.getCode(), ErrorCodeEnum.SYSTEM_ERROR.getMsg());
        }
    }


}
